<template>
  <div class="app-container">
    <el-alert
      title="举报中心"
      type="warning"
      description="不能让一个坏人污染了空气"
    />
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row>
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="用户名" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.stu_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.stu_phone }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="100">
        <template slot-scope="scope">
          <el-button size="small" type="text" @click="delRow(scope.row)">拉黑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :page-size="12"
      :pager-count="11"
      :total="count"
      layout="prev, pager, next"
      @current-change="page"
    />
  </div>
</template>
<script>
import { getList } from '@/api/ask'
import { nowTime } from '@/utils/index'
import { getUsers, delUser } from '@/api/user'
export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      count: 0
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    page(idx) {
      getList(idx).then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          data[i].stu_time = nowTime(data[i].stu_time)
        }
        this.list = data
        this.listLoading = false
      })
    },
    fetchData() {
      this.listLoading = true
      getUsers().then(response => {
        const data = response.data
        this.list = data
        this.listLoading = false
      })
    },
    showMore(item) {
      console.log(item)
    },
    delRow(obj) {
      delUser(obj.stu_name).then((res) => {
        this.$message(res.message)
        setTimeout(this.fetchData(), 2000)
      })
    }
  }
}
</script>
